package bean;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import dao.ClientDAO;
import dao.DiscountCategoryDAO;
import dao.JPA;
import entity.Client;
import entity.DiscountCategory;

@Named
@RequestScoped
public class CreateClientBean implements Serializable {

	@Inject @JPA
    private DiscountCategoryDAO discountCategoryDAO;
	@Inject @JPA
    private ClientDAO clientDAO;
	private Client client = new Client();
	private List<DiscountCategory> discountCategoryList;		
	
	@PostConstruct
	private void init() {		
		discountCategoryList = discountCategoryDAO.findAll();
	}
	
	public String createClient() {
		clientDAO.persist(client);
		FacesContext facesContext = FacesContext.getCurrentInstance();		
		facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Client profile created", "Client profile created"));
		return "back";
	}
	
	public Client getClient() {
		return client;
	}
	
	public List<DiscountCategory> getDiscountCategoryList() {
		return discountCategoryList;
	}
	
}